package com.example.newsapp.ui.components.otherComponent.newsDetailComponent

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextIndent
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

/**
 * 新闻详情页主体内容
 *
 * @param title 新闻标题
 * @param source 新闻来源
 * @param pictureId 图片id
 * @param textList 新闻内容
 */
@Composable
fun BodyNewsDetails(
    title: String,
    source: String,
    pictureId: Int,
    textList: List<String>,
    modifier: Modifier = Modifier
) {
    LazyColumn {
        // 新闻标题
        item {
            Text(
                text = title,
                style = MaterialTheme.typography.headlineLarge,
                fontWeight = FontWeight.Bold,
                modifier = Modifier.padding(bottom = 8.dp)
            )
        }
        // 新闻出处
        item {
            if (source != "") {
                Text(
                    text = "来源：${source}",
                    style = MaterialTheme.typography.bodyMedium,
                    color = Color(0xFF676767),
                    modifier = Modifier.padding(bottom = 16.dp)
                )
            }
        }
        // 新闻图片
        item {
            if (pictureId != 0) {
                Image(
                    painter = painterResource(id = pictureId),
                    contentDescription = "新闻图片",
                    contentScale = ContentScale.Crop,
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(bottom = 15.dp)
                )
            }
        }
        itemsIndexed(textList) { index, text ->
            Text(
                text = textList[index],
                style = TextStyle(
                    textIndent = TextIndent(firstLine = 34.sp)
                ),
                fontSize = 17.sp,
                lineHeight = 27.sp
            )
            Spacer(modifier.height(27.dp))
        }
    }
}